/*           Copyright(c) 2007-2008 Dave Sexton            *
 *                   XmlTreeView Control                   *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.XPath;

namespace DaveSexton.Controls
{
	public enum ElementChangeType
	{
		CheckChanged, 
		Created, 
		Edited, 
		Deleted, 
		Moved, 
		Updated, 
		Replaced
	}

	/// <summary>
	/// Provides arguments for the <see cref="IXmlTreeViewDataManager.ElementChanged"/> event.
	/// </summary>
	[Serializable]
	public class ElementChangedEventArgs : EventArgs
	{
		#region Public Properties
		public IXPathNavigable Element
		{
			get
			{
				return element;
			}
		}

		/// <remarks>
		/// This property returns <see langword="null"/> except for when the <see cref="Change"/> property has the following values: 
		/// <list type="table">
		/// <listheader>
		/// <term>Value of <see cref="Change"/></term>
		/// <description>Value of this property</description>
		/// </listheader>
		/// <item>
		/// <term><see cref="ElementChangeType.Moved"/></term>
		/// <description>The element that was dragged by the user, although it is no longer part of the document.</description>
		/// </item>
		/// <item>
		/// <term><see cref="ElementChangeType.Updated"/></term>
		/// <description>The element that was previously associated with the current <see cref="Element"/>'s tree node before the binding was updated.</description>
		/// </item>
		/// <item>
		/// <term><see cref="ElementChangeType.Replaced"/></term>
		/// <description>The element that was previously associated with the current <see cref="Element"/>'s tree node before it was replaced.</description>
		/// </item>
		/// </list>
		/// </remarks>
		public IXPathNavigable OriginalElement
		{
			get
			{
				return originalElement;
			}
		}

		public ElementChangeType Change
		{
			get
			{
				return change;
			}
		}
		#endregion

		#region Private / Protected
		private readonly IXPathNavigable element, originalElement;
		private readonly ElementChangeType change;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="ElementChangedEventArgs" /> class.
		/// </summary>
		public ElementChangedEventArgs(IXPathNavigable element, ElementChangeType change)
		{
			if (element == null)
				throw new ArgumentNullException("element");

			if (!Enum.IsDefined(typeof(ElementChangeType), change))
				throw new System.ComponentModel.InvalidEnumArgumentException("change", (int) change, typeof(ElementChangeType));

			this.element = element;
			this.change = change;
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="ElementChangedEventArgs" /> class.
		/// </summary>
		public ElementChangedEventArgs(IXPathNavigable originalElement, IXPathNavigable element, ElementChangeType change)
			: this(element, change)
		{
			if (originalElement == null)
				throw new ArgumentNullException("originalElement");

			this.originalElement = originalElement;
		}
		#endregion
	}
}
